<template>
    <div class="achievement">

        <div class="mb8">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="onAdd"
                       v-hasPermi="['oms:omstask:achievement']">录入业绩</el-button>
            <el-button type="success" icon="el-icon-download" size="mini" @click="handleExport"
                       v-hasPermi="['oms:productDetail:export']">导出</el-button>
        </div>

        <el-table v-loading="loading" :data="tableList">
            <el-table-column label="日期" prop="achievementDate"/>
            <el-table-column label="姓名" prop="achievementName"/>
            <el-table-column label="工号" prop="achievementJobno"/>
            <el-table-column label="订单" prop="taskNo"/>
            <el-table-column label="货号" prop="goodsNo"/>
            <el-table-column label="品名规格" prop="nameSku"/>
            <el-table-column label="包装方式" prop="packingType"/>
            <el-table-column label="数量" prop="achievementNum"/>
            <el-table-column label="单价" prop="achievementPrice"/>
            <el-table-column label="金额" prop="achievementMoney"/>

            <el-table-column label="名称" prop="productName"/>
            <el-table-column label="插条" prop="achievementCutting"/>
            <el-table-column label="颜色" prop="achievementColor"/>
            <el-table-column label="微机数量" prop="microcomputerCount"/>
            <el-table-column label="待机数量" prop="machineCount"/>
            <el-table-column label="合计数量" prop="achievementTotal"/>

            <el-table-column label="备注" prop="achievementRemark"/>
        </el-table>
        <!--分页-->
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                    @pagination="getList"/>

    </div>
</template>

<script>
import {responseEnum} from "../../../../const/const";
import {getAchievement, getHalfTask} from "../api";

export default {
    props: ['taskId', 'workshop'],
    components: {},
    data() {
        return {
            loading: true,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                taskId: null,
                achievementWorkshop: null
            },
            // 总条数
            total: 0,
            // 表格数据
            tableList: [],
        };
    },
    watch: {
        workshop(val, old){
            this.queryParams.taskId = this.taskId;
            this.queryParams.achievementWorkshop = this.workshop;
            this.getList();
        }
    },
    created() {
        this.getList();
    },
    methods: {

        /** 查询列表 */
        getList() {
            this.loading = true;
            getAchievement(this.queryParams).then(res => {
                if (res.code === responseEnum.success) {
                    this.tableList = res.rows || [];
                    this.total = res.total || 0;
                }
            }).finally(() => this.loading = false);
        },

        onAdd() {
            this.$router.push({path: '/ProduceTask/detail/addAchievement', query: {...this.$route.query}})
        },
        /** 导出按钮操作 */
        handleExport() {
            const params = {...this.queryParams, taskId: this.taskId};
            this.download('/oms/omstask/taskAchievementexport', params, `业绩_${new Date().getTime()}.xlsx`)
        },
    }
};

</script>

<style lang="scss" scoped>

</style>
